package com.starsea.book.ui.newpage.adapter

import android.content.Context
import android.text.TextUtils
import android.view.ViewGroup
import com.blankj.utilcode.util.SpanUtils
import com.starsea.book.R
import com.starsea.book.base.adapter.ItemViewHolder
import com.starsea.book.base.adapter.RecyclerAdapter
import com.starsea.book.databinding.ItemSignHorListBinding
import com.starsea.book.ui.newpage.entity.Today
import com.starsea.book.ui.newpage.utils.finialDouble
import com.starsea.book.ui.widget.recycler.ItemTouchCallback
import com.starsea.book.utils.visible

class SignDetailsProgressAdapter(
    context: Context,
    var today: Today
) :
    RecyclerAdapter<Today, ItemSignHorListBinding>(context),
    ItemTouchCallback.Callback {


    override fun getViewBinding(parent: ViewGroup): ItemSignHorListBinding {
        return ItemSignHorListBinding.inflate(inflater, parent, false)
    }

    override fun registerListener(holder: ItemViewHolder, binding: ItemSignHorListBinding) {

    }

    override fun convert(
        holder: ItemViewHolder,
        binding: ItemSignHorListBinding,
        item: Today,
        payloads: MutableList<Any>
    ) {
        binding.run {
//            tvTitle.text = item.time

            tvDay.text = "${item.time ?: ""}天"

            rtvCoin.text = if (item.amountType == 1)
                SpanUtils().append((item.amount ?: "0").toDouble().finialDouble())
                    .append("\n金币")
                    .setFontSize(10, true)
                    .create()
            else SpanUtils().append((item.amount ?: "0").toDouble().finialDouble())
                .append("\n元")
                .setFontSize(10, true)
                .create()


            if ((today.time!!.toInt() + 1) == item.time!!.toInt()) {
                rtvSignTag.visible(true)
            } else {
                rtvSignTag.visible(false)
            }

            if (item.time!!.toInt() < today.time!!.toInt()) {
                ivBg.setImageResource(R.mipmap.icon_sign_bg_unsel)
                rtvLine.isSelected = true

            } else {
                ivBg.setImageResource(R.mipmap.icon_sign_bg_sel)
                rtvLine.isSelected = false

            }

            if (TextUtils.isEmpty(item.recordId)){
                ivIsSign.visible(false)
            }else{
                ivIsSign.visible(true)
            }

        }
    }


}